package educationaladministrationsystem.CSM.Controller.StudentAndTeacher.Teacher;

import educationaladministrationsystem.Class.Course;
import educationaladministrationsystem.Result.Result;
import educationaladministrationsystem.CSM.Mapper.Service.StudentAndTeacher.Teacher.TeacherCourseManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("Teacher/CourseManagement")
@RestController
public class TeacherCourseManagementController {
    @Autowired
    private TeacherCourseManagementService teacherCourseManagementService;

    @GetMapping("/getAllCourse")
    public Result getAllCourse(@RequestParam String UID, @RequestParam int page, @RequestParam int pageSum) {
        return Result.success(teacherCourseManagementService.getAllCourse(UID, page, pageSum));
    }

    @GetMapping("/getTeacherNameById")
    public Result getTeacherNameById(@RequestParam String UID) {
        return Result.success(teacherCourseManagementService.getTeacherNameById(UID));
    }

    //    判断课程是否有冲突
    @GetMapping("/isTheSameTimeCourse")
    public Result isTheSameTimeCourse(@RequestParam String UID, @RequestParam int day, @RequestParam int startTime, @RequestParam int constTime, @RequestParam(required = false) String classId) {
        return Result.success(teacherCourseManagementService.isTheSameTimeCourse(UID, day, startTime, constTime, classId));
    }

    //    获取课程号
    @GetMapping("/getCourseId")
    public Result getCourseId() {
        return Result.success(teacherCourseManagementService.getCourseId());
    }

    @PostMapping("/addNewCourse")
    public Result addNewCourse(@RequestBody Course course) {
        teacherCourseManagementService.addNewCourse(course);
        return Result.success();
    }

    //    获取课程信息
    @GetMapping("/getCourseById")
    public Result getCourseById(@RequestParam String id) {
        return Result.success(teacherCourseManagementService.getCourseById(id));
    }

    @PostMapping("/updateCourse")
    public Result updateCourse(@RequestBody Course course, @RequestParam String oldId) {
        teacherCourseManagementService.updateCourse(course, oldId);
        return Result.success();
    }

    @PostMapping("/deleteCourse")
    public Result deleteCourse(@RequestParam String id) {
        teacherCourseManagementService.deleteCourse(id);
        return Result.success();
    }

    @GetMapping("/getCoursePage")
    public Result getCoursePage(@RequestParam String id, @RequestParam int pageSum) {
        return Result.success(teacherCourseManagementService.getCoursePage(id, pageSum));
    }
}
